class Solution:
    def reconstructQueue(self, people):
        people.sort(key=lambda x:[-x[0],x[1]])
        # print(people)
        for i in range(1,len(people)):
            if people[i][1]!=i:
                tmp = people[i]
                people[tmp[1]+1:i+1] = people[tmp[1]:i]
                people[tmp[1]] = tmp
        return people


if __name__ == '__main__':
    so = Solution()
    num = [[6,0],[5,0],[4,0],[3,2],[2,2],[1,4]]
    r = so.reconstructQueue(num)
    print(r)
